package com.dycx.payment.enums;

import lombok.Getter;

import java.util.*;

/**
 * 支付类型
 */
@Getter
public enum PayStatusEnum {

    UNPAID(1, "未支付", "danger"),
    HAVE_PAID(2, "已支付", "success"),
    REFUND(3, "已退款", "warning");

    private final Integer code;
    private final String name;
    private final String style;

    PayStatusEnum(Integer code, String name, String style) {
        this.code = code;
        this.name = name;
        this.style = style;
    }

    public static PayStatusEnum converter(Integer code) {
        return Arrays.stream(values()).filter(en -> en.code.equals(code)).findAny().orElse(UNPAID);
    }

    /**
     * 转为数据
     *
     * @return 枚举对象数组
     */
    public static List<Map<String, Object>> getList() {
        List<Map<String, Object>> list = new ArrayList<>();
        for (PayStatusEnum item : PayStatusEnum.values()) {
            Map<String, Object> map = new HashMap<>();
            map.put("code", item.getCode());
            map.put("name", item.getName());
            list.add(map);
        }
        return list;
    }
}
